/**
 * 
 */
package model;

import java.util.Iterator;

import fpt.com.Product;

public class ModelShop extends java.util.Observable implements
		fpt.com.ProductList {

	private static final long serialVersionUID = -4260048265856130202L;

	private ProductList productList;

	public ModelShop() {
		super();
		productList = new ProductList();
	}

	@Override
	public Iterator<Product> iterator() {
		return productList.iterator();
	}

	@Override
	public boolean add(Product p) {
		boolean b = productList.add(p);
		super.setChanged();
		super.notifyObservers(p);
		return b;
	}

	@Override
	public boolean delete(Product product) {
		boolean b = productList.delete(product);
		super.setChanged();
		super.notifyObservers(product);
		return b;
	}

	@Override
	public int size() {
		return productList.size();
	}

	@Override
	public Product findProductById(long id) {
		return productList.findProductById(id);
	}

	@Override
	public Product findProductByName(String name) {
		return productList.findProductByName(name);
	}

	public model.Product[] getProductArray() {
		model.Product[] products = new model.Product[0];
		return productList.toArray(products);
	}

	public ProductList getProductList() {
		return productList;
	}

	public void setProductList(ProductList productList) {
		this.productList = productList;
		super.setChanged();
		super.notifyObservers(productList);

	}
}
